package com.zjitc.service.impl;

import com.zjitc.dao.CartDao;
import com.zjitc.dao.ProductDao;
import com.zjitc.model.Cart;
import com.zjitc.model.Product;
import com.zjitc.service.CartService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/5/14 16:47
 * @description:
 */
@Service
public class CartServiceImpl implements CartService {

  @Autowired
  private CartDao cartDao;

  @Autowired
  private ProductDao productDao;

  @Override
  public List<Cart> findCartByUid(Integer uid) {
    List<Cart> list = cartDao.findCartByUid(uid);
    List<Product> productList = null;
    for (Cart m:list){
      Product product = new Product();
      int productId = m.getPid();
      product = productDao.showProduct(productId);
      m.setProduct(product);
    }
    return list;
  }

  @Override
  public int deleteCart(String cartid) {
    int count = cartDao.deleteCart(cartid);
    return count;
  }

  @Override
  public int addCart(Cart cart) {
    int quantity = cartDao.addCart(cart);
    return quantity;
  }

  @Override
  public void cleanCart(Integer uid) {
     cartDao.cleanCart(uid);

  }
}
